package com.blockmeta.bbs.immodule.widget.msgview;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.blockmeta.bbs.baselibrary.utils.LoadPicUtil;
import com.blockmeta.bbs.immodule.R;
import com.blockmeta.bbs.immodule.bean.databean.PostContentBean;
import com.blockmeta.bbs.immodule.dao.ChatMessage;
import com.chad.library.adapter.base.BaseViewHolder;

public class GoodThingShareMsgView<T extends ChatMessage> extends MsgView<T>{

    public GoodThingShareMsgView(Context context) {
        super(context);
    }

    @Override
    public int getLayoutId() {
        return R.layout.im_chat_shareitem2;
    }

    @Override
    public void convert(BaseViewHolder helper, T item, T lastItem) {
        super.convert(helper, item, lastItem);
        super.bindCommonControl(helper, item, lastItem);

        PostContentBean contentBean = getContentBean(item, PostContentBean.class);
        String deepLink = TextUtils.isEmpty(contentBean.getUrl()) ? String.format("blockmeta://news/detail?id=%s"
                , contentBean.getId()) : contentBean.getUrl();
        String linkText = "分享好物";

        //发送消息！
        if (item.getType() == ChatMessage.TYPE_SEND) {
            ImageView icon = helper.getView(R.id.right_img_icon);
            LoadPicUtil.loadWithPicasso2(icon, contentBean.getImg());
            helper.setText(R.id.right_title, contentBean.getName());
            helper.setText(R.id.right_link, linkText);
            View contentLayout = helper.getView(R.id.chat_item_layout_content);
            contentLayout.setTag(deepLink);
            helper.addOnClickListener(R.id.chat_item_layout_content);
        } else {
            //接收消息
            ImageView icon = helper.getView(R.id.left_img_icon);
            LoadPicUtil.loadWithPicasso2(icon, contentBean.getImg());
            helper.setText(R.id.left_title, contentBean.getName());
            helper.setText(R.id.left_link, linkText);
            View contentLayout = helper.getView(R.id.left_chat_item_layout_content);
            contentLayout.setTag(deepLink);
            helper.addOnClickListener(R.id.left_chat_item_layout_content);
        }

    }

}
